import request from '@/utils/request'

// 权限管理相关请求函数
const api_name = '/admin/acl/permission'

export default {
    // 请求获取权限菜单列表
    getPermissionList() {
        return request({
            url: `${api_name}`,
            method: 'get'
        })
    },

    // 递归删除菜单
    removePermission(id) {
        return request({
            url: `${api_name}/remove/${id}`,
            method: 'delete'
        })
    },

    // 新增菜单
    addPermission(permission) {
        return request({
            url: `${api_name}/save`,
            method: "post",
            data: permission
        })
    },

    // 修改
    updatePermission(permission) {
        return request({
            url: `${api_name}/update`,
            method: "put",
            data: permission
        })
    },

    // 根据角色获取菜单
    toAssign(roleId) {
        return request({
            url: `${api_name}/toAssign/${roleId}`,
            method: 'get'
        })
    },

    // 给角色分配权限
    doAssign(roleId, permissionId) {
        return request({
            url: `${api_name}/doAssign`,
            method: "post",
            params: { roleId, permissionId }, // 'id1,id2,id3'
        })
    }
}